<template>
  <editor-layout class="edit" @ok="handleOk"  v-on="$listeners">
    <el-form :model="model" class="customForm" size="small" label-width="90px">
      <el-row :gutter="10">
        <el-col :span="24">
          <el-form-item label="字段英文名" prop="prop">
            <el-input v-model="model.prop" placeholder="字段英文名" clearable/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="字段中文名" prop="name">
            <el-input v-model="model.name" placeholder="字段中文名" clearable/>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="最大值" prop="max">
            <el-input-number v-model="model.max" style="width: 100%;" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <template v-slot:footer>
      <el-button v-show="model.id" type="danger" size="small" @click="handleDel">删除</el-button>
      <el-button size="small" @click="handleCancel">取消</el-button>
      <el-button size="small" type="primary" @click="handleOk">确定</el-button>
    </template>
  </editor-layout>
</template>

<script>

export default {
  name: 'column-edit',
  cnName: 'column-edit',
  components: {
  },
  props: {
    data: Object
  },
  data() {
    return {
      model: {
        id: '',
        prop: '',
        name: '',
        max: 100
      }
    }
  },
  methods: {
    init() {
      if(this.data) {
        const model = {...this.data}
        this.model = {
          ...model
        }
      }
    },
    handleCancel() {
      this.$emit('cancel')
    },
    handleDel() {
      this.$emit('on-ok', 0, this.model.id)
    },
    handleOk() {
      const param = {...this.model}
      if(!param.id) {
        param.id = new Date().getTime()
      }

      this.$emit('on-ok', 1, param)
    }
  },
  mounted() {
    this.init()
  }
}
</script>

<style lang="less" scoped>
.column-edit {
}
</style>
